package rs.mbs2.epics.server.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rs.mbs2.epics.server.entity.Photo;
import rs.mbs2.epics.server.session.dao.localinterface.PhotoDaoLocal;

@SuppressWarnings("serial")
public class PreEditPhotoController extends HttpServlet {

	@EJB
	private PhotoDaoLocal photoDao;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		String idString = request.getParameter("id");
		Integer id = Integer.parseInt(idString);
		
		Photo photo = photoDao.findById(id);
		
		request.setAttribute("photo", photo);
		
		getServletContext().getRequestDispatcher("/editPhoto.jsp").forward(request, response);
		return;
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
}
